package xinxin.com.CommandPattern.Waiter;

import xinxin.com.CommandPattern.Command.Command;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class Waiter {
    private List<Command> orders = new LinkedList<Command>();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    // 设置订单
    public void SetOrder(Command command) {
        if (command.toString() == "命令模式.BakeChickenWingCommand") {
            System.out.println("服务员：鸡翅没有了，请点别的烧烤。");
        } else {
            orders.add(command);
            System.out.println("增加订单：" + command.toString() + " 时间：" + df.format(new Date()));
        }
    }

    // 取消订单
    public void CancleOrder(Command command) {
        orders.remove(command);
        System.out.println("取消订单：" + command.toString() + " 时间：" + df.format(new Date()));
    }

    // 通知执行
    public void Notify() {
        for (Command command : orders) {
            command.ExcuteCommand();
        }
    }
}
